package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordDrink;
import com.letian.record.service.IRecordDrinkService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 饮用记录Controller
 * 
 * @author bmz
 * @date 2023-07-13
 */
@RestController
@RequestMapping("/record/drink")
public class RecordDrinkController extends BaseController
{
    @Autowired
    private IRecordDrinkService recordDrinkService;

    /**
     * 查询饮用记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:drink:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordDrink recordDrink)
    {
        startPage();
        List<RecordDrink> list = recordDrinkService.selectRecordDrinkList(recordDrink);
        return getDataTable(list);
    }

    /**
     * 查询饮用记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:drink:list')")
    @GetMapping("/my/list")
    public TableDataInfo myList(RecordDrink recordDrink)
    {
        startPage();
        recordDrink.setCreateBy(getUsername());
        List<RecordDrink> list = recordDrinkService.selectRecordDrinkList(recordDrink);
        return getDataTable(list);
    }

    /**
     * 查询饮用记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:drink:list')")
    @GetMapping("/list/today")
    public TableDataInfo listToday(RecordDrink recordDrink)
    {
        startPage();
        recordDrink.setCreateBy(getUsername());
        List<RecordDrink> list = recordDrinkService.selectRecordDrinkListToday(recordDrink);
        return getDataTable(list);
    }

    /**
     * 导出饮用记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:drink:export')")
    @Log(title = "饮用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordDrink recordDrink)
    {
        List<RecordDrink> list = recordDrinkService.selectRecordDrinkList(recordDrink);
        ExcelUtil<RecordDrink> util = new ExcelUtil<RecordDrink>(RecordDrink.class);
        util.exportExcel(response, list, "饮用记录数据");
    }

    /**
     * 获取饮用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:drink:query')")
    @GetMapping(value = "/{drinkId}")
    public AjaxResult getInfo(@PathVariable("drinkId") Long drinkId)
    {
        return success(recordDrinkService.selectRecordDrinkByDrinkId(drinkId));
    }

    /**
     * 新增饮用记录
     */
    @PreAuthorize("@ss.hasPermi('record:drink:add')")
    @Log(title = "饮用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordDrink recordDrink)
    {
        recordDrink.setCreateBy(getUsername());
        return toAjax(recordDrinkService.insertRecordDrink(recordDrink));
    }

    /**
     * 修改饮用记录
     */
    @PreAuthorize("@ss.hasPermi('record:drink:edit')")
    @Log(title = "饮用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordDrink recordDrink)
    {
        recordDrink.setUpdateBy(getUsername());
        return toAjax(recordDrinkService.updateRecordDrink(recordDrink));
    }

    /**
     * 删除饮用记录
     */
    @PreAuthorize("@ss.hasPermi('record:drink:remove')")
    @Log(title = "饮用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drinkIds}")
    public AjaxResult remove(@PathVariable Long[] drinkIds)
    {
        return toAjax(recordDrinkService.deleteRecordDrinkByDrinkIds(drinkIds));
    }
}
